package com.fengqilin.myapplication;

import android.util.Log;

public class CashierEntity {
    MoneyEntity[] entities = new MoneyEntity[9];
    public MoneyEntity Coin0_1 = new MoneyEntity();

    public MoneyEntity Coin0_5 = new MoneyEntity();

    public MoneyEntity Coin1 = new MoneyEntity();

    public MoneyEntity m1 = new MoneyEntity();

    public MoneyEntity m10 = new MoneyEntity();

    public MoneyEntity m100 = new MoneyEntity();

    public MoneyEntity m20 = new MoneyEntity();

    public MoneyEntity m5 = new MoneyEntity();

    public MoneyEntity m50 = new MoneyEntity();

    public CashierEntity() {
        this.m100.money = 1000;
        this.m50.money = 500;
        this.m20.money = 200;
        this.m10.money = 100;
        this.m5.money = 50;
        this.m1.money = 10;
        this.Coin1.money = 10;
        this.Coin0_5.money = 5;
        this.Coin0_1.money = 1;
        entities[0] = this.Coin0_1;
        entities[1] = this.Coin0_5;
        entities[2] = this.Coin1;
        entities[3] = this.m1;
        entities[4] = this.m5;
        entities[5] = this.m10;
        entities[6] = this.m20;
        entities[7] = this.m50;
        entities[8] = this.m100;
    }

    public MoneyEntity getCoin0_1() {
        return Coin0_1;
    }

    public void setCoin0_1(MoneyEntity coin0_1) {
        Coin0_1 = coin0_1;
    }

    public MoneyEntity getCoin0_5() {
        return Coin0_5;
    }

    public void setCoin0_5(MoneyEntity coin0_5) {
        Coin0_5 = coin0_5;
    }

    public MoneyEntity getCoin1() {
        return Coin1;
    }

    public void setCoin1(MoneyEntity coin1) {
        Coin1 = coin1;
    }

    public MoneyEntity getM1() {
        return m1;
    }

    public void setM1(MoneyEntity m1) {
        this.m1 = m1;
    }

    public MoneyEntity getM10() {
        return m10;
    }

    public void setM10(MoneyEntity m10) {
        this.m10 = m10;
    }

    public MoneyEntity getM100() {
        return m100;
    }

    public void setM100(MoneyEntity m100) {
        this.m100 = m100;
    }

    public MoneyEntity getM20() {
        return m20;
    }

    public void setM20(MoneyEntity m20) {
        this.m20 = m20;
    }

    public MoneyEntity getM5() {
        return m5;
    }

    public void setM5(MoneyEntity m5) {
        this.m5 = m5;
    }

    public MoneyEntity getM50() {
        return m50;
    }

    public void setM50(MoneyEntity m50) {
        this.m50 = m50;
    }

    public int all() {
        return this.Coin0_1.sum()
                + this.Coin0_5.sum()
                + this.Coin1.sum()
                + this.m1.sum()
                + this.m5.sum()
                + this.m10.sum()
                + this.m20.sum()
                + this.m50.sum()
                + this.m100.sum();
    }

    public static class MoneyEntity {
        public int money;

        public int num;

        public int shangjiao;

        public int sum() {
            return this.money * this.num;
        }

        public int isCheck(int paramInt) {
            this.shangjiao = shangJiaoMoney(paramInt);
            return paramInt - this.shangjiao * this.money;
        }

        private int shangJiaoMoney(int paramInt) {
            paramInt /= this.money;
            return (paramInt != 0) ? (Math.min(paramInt, this.num)) : 0;
        }

    }

    public int sunChange() {
        int j = all() - 10000;
        if (j < 0)
            return j;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("sunChange: number > ");
        stringBuilder.append(j);
        Log.i("MainActivity", stringBuilder.toString());
        for (MoneyEntity entity : this.entities) {
            j = entity.isCheck(j);
            if (j == 0) return 0;
        }
        return j;
    }
}
